import { createStore, applyMiddleware, compose } from 'redux'
import ReduxThunk from 'redux-thunk'
import RootReducer from '../reducers'
//applyMiddleware来自redux可以包装 store 的 dispatch
//thunk作用是使action创建函数可以返回一个function代替一个action对象


const configureStore = (initialState) => {
    const EnhancerCompose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
    // console.log("这是开发环境")
    const store = createStore(
        RootReducer,
        initialState,
        EnhancerCompose(
            applyMiddleware( ReduxThunk ),
        )
    )

    if( module.hot ){
        module.hot.accept('../reducers',()=>{
            store.replaceReducer(RootReducer)
        })
    }

    return store
}

export default configureStore;